package com.icedata.sika.util

import com.icedata.sika.bridge.SikaContact
import com.icedata.sika.bridge.SikaEvent
import com.icedata.sika.bridge.SikaMessageChain

object Logger {
    @JvmStatic
    fun logError(e: Exception) {
        // 添加Exception基础信息
        System.err.println(
            """
错误类型: ${e.javaClass}
原因: 
消息: ${e.message}
栈追踪: 
${getExceptionStack(e)}""".trimIndent()
        )
    }

    private fun getExceptionStack(e: Exception): String {
        val result = StringBuilder()
        for (s in e.stackTrace) {
            result.append("\tat ").append(s).append("\r\n")
        }
        return result.toString()
    }

    fun logEvent(event: SikaEvent) {
        println("$event")
    }

    fun logSend(messageChain: SikaMessageChain, contact: SikaContact) {
        println("\u001b[0;33;40mSika:S/Bot:(${contact.id})${contact.name}:${messageChain}\u001b[0m")
    }

    fun logDebug(type: String, message: String) {
        println("\u001b[0;32;40mSika:D/Debug:[$type]:$message\u001b[0m")
    }

    fun logDebug(message: String) {
        logDebug("Debug", message)
    }
}